package com.qin.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qin.mall.dao.PmsSkuStockDao;
import com.qin.mall.domain.PmsSkuStock;
import com.qin.mall.mapper.PmsSkuStockMapper;
import com.qin.mall.service.PmsSkuStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
* @author 覃剑
* @description 针对表【pms_sku_stock(sku的库存)】的数据库操作Service实现
* @createDate 2022-11-07 09:45:36
*/
@Service
public class PmsSkuStockServiceImpl extends ServiceImpl<PmsSkuStockMapper, PmsSkuStock>
    implements PmsSkuStockService {
    
    @Autowired
    private PmsSkuStockMapper skuStockMapper;
    
    @Autowired
    private PmsSkuStockDao skuStockDao;

    // TODO 根据产品id和skuCode模糊搜索
    @Override
    public List<PmsSkuStock> getList(Long pid, String keyword) {
        QueryWrapper<PmsSkuStock> wrapper = new QueryWrapper<>();
        wrapper.eq("product_id",pid);
        if (!StringUtils.isEmpty(keyword)) {
            wrapper.like("sku_code",keyword);
        }
        List<PmsSkuStock> stocks = skuStockMapper.selectList(wrapper);
        return stocks;
    }

    // TODO 批量更新商品库存信息
    @Override
    public int stockUpdate(Long pid,List<PmsSkuStock> skuStockList) {
        int list = skuStockDao.replaceList(skuStockList);
        return list;
    }
}




